package com.daiTest.controller;

import com.daiTest.pojo.User;
import com.daiTest.service.UserService;
import com.daiTest.untils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user")
@CrossOrigin
public class UserController {

    @Autowired
    private UserService userService;

    /*根据账号 查询用户对象 */
    @PostMapping("login")
    public Result login(@RequestBody User user) {

        Result result = userService.login(user);
        return result;
    }

    /*根据token获取用户数据*/
    @GetMapping("getUserInfo")
    public Result getUserInfo(@RequestHeader String token) {
        Result result = userService.getUserInfo(token);

        return result;
    }

    /*检查账号是否可用*/
    @PostMapping("checkUserName")
    public Result check(String username) {
        Result result = userService.cheakUserName(username);
        return result;
    }

    /*用户注册 */
    @PostMapping("regist")
    public Result regist(@RequestBody User user){
       Result result= userService.regist(user);
       return result;
    }

    /*检验token是否过期*/
    @GetMapping("checkLogin")
    public Result checkLogin(@RequestHeader String token){
      Result result=  userService.checkLogin(token);
        return result;
    }
}
